package com.ytc.util;

import com.ytc.model.User;
import com.ytc.service.UserService;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 详细介绍类情况.
 *
 * @ClassName UserUtil
 * @Author zk
 * @Date 2023/1/13
 * @Version 1.0
 */
public class UserUtil {
    //获取用户
    public static User getUser(HttpServletRequest request){
        return (User) request.getSession().getServletContext().getAttribute("user");
    }

    //查询阅读权限
    public static boolean readFlag(User user, UserService userService){
        if(user!=null){
            Integer rid = userService.isOrNotVip(user.getUId());
            if (rid==2||rid==4) {
                return true;//有权限
            }
        }
        return false;//无权限
    }

    //判断会员是否到期
    public static boolean vipIsOrNotDue(String date) throws ParseException {
        Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
        Date now = new Date();
        if(parse.getTime()> now.getTime())
            return false;//没过期
        else
            return true;//过期了
    }

    public static void main(String[] args) throws ParseException {
        String date = "2023-01-13 19:29:28";
        String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println(format);


    }
}
